<?php
/// O'My Friends: Personal Social Network Graph on Facebook
/// author : Minkyu Shim (minkyu.shim@gmail.com
function getTemplateHTML($title){

    $html = null;
    $html = file_get_contents("./template/main.html");
    $html = str_ireplace("[##_DOCUMENT_HEADER_##]", getDocumentHeaderHTML($title), $html);
    $html = str_ireplace("[##_DOCUMENT_BODY_HEADER_##]", getDocumentBodyHeaderHTML($title), $html);

    $regex = "/^.*\/(.*)\..*$/i";
    preg_match($regex, $_SERVER['SCRIPT_NAME'], $matches);
    
    $contentHtml = null;
    $scriptHtml = null;
    switch($matches[1]){
        case "index":
            $contentHtml = getIndexContentHTML();
            $scriptHtml = getIndexScriptHTML();
            break;
        case "friendship":
            $contentHtml = getFriendshipContentHTML();
            $scriptHtml = getFriendshipScriptHTML();
            break;
        case "testapplet":
            $contentHtml = getIndexContentHTML();
            $scriptHtml = getTestAppletScriptHTML();
            break;
    }
    $html = str_ireplace("[##_DOCUMENT_HEADER_JAVASCRIPT_##]", $scriptHtml, $html);
    $html = str_ireplace("[##_DOCUMENT_BODY_CONTENT_##]", $contentHtml, $html);

    
    return $html;
}

function getDocumentHeaderHTML($subtitle){
    $html = file_get_contents('./template/document_header.html');
    $html = str_ireplace("[##_TITLE_##]", SERVICE_TITLE, $html);
    $html = str_ireplace("[##_SUBTITLE_##]", $subtitle, $html);
    return $html;
}

function getDocumentBodyHeaderHTML($subtitle){
    $html = file_get_contents("./template/document_body_header.html");
    $html = str_ireplace("[##_SUBTITLE_##]", $subtitle, $html);
    return $html;
}

function getIndexScriptHTML(){
    $html = file_get_contents("./template/index_javascript.html");
    return $html;
}

function getIndexContentHTML(){
    $html = file_get_contents("./template/index_content.html");
    return $html;
}

function getFriendshipContentHTML(){
    $html = file_get_contents("./template/friendship_content.html");
    return $html;    
}

function getFriendshipScriptHTML(){
    $html = file_get_contents("./template/friendship_javascript.html");
    return $html;
}

function getTestAppletScriptHTML(){
    $html = file_get_contents("./template/testApplet_javascript.html");
    return $html;
}
``?>